package cn.yonyong.base.project.config.AOP;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Describtion Todo
 * @Author yonyong
 * @Date 2019/10/12 15:53
 * @Version 1.0.0
 **/
@Aspect
@Component
public class DeprecatedCodeAspect {

    @Pointcut(value = "execution(public * cn.yonyong.base.project.service..*.*(..))")
    private void pointcut(){
        System.out.println(this.getClass());
    }

//    @Before("poingcut()")
//    public Object doBefore(){
//        Thread.currentThread().getId();
//        Object result = null;
//        return result;
//    }

    @Around("pointcut()")
    public Object doAround(ProceedingJoinPoint proceedingJoinPoint){
//        Thread.currentThread().getId();
        StackTraceElement[] stack = (new Throwable()).getStackTrace();
        for (int i = 0; i < stack.length; i++) {
            StackTraceElement ste = stack[i];
            System.out.println(ste.getClassName() + "." + ste.getMethodName() + "(...);");
            System.out.println(i + "--" + ste.getMethodName());
            System.out.println(i + "--" + ste.getFileName());
            System.out.println(i + "--" + ste.getLineNumber());
        }
        Object result = null;
        try {
            result = proceedingJoinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return result;
    }

//    @After("poingcut()")
//    public Object doAfter(){
//        Thread.currentThread().getId();
//        Object result = null;
//        return result;
//    }
}
